﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using EntityObject;
using SharedLibraries.Constants;
using ThangNM_LIB.DB;
using ThangNM_LIB.EO;
using ThangNM_LIB.FUNC;

namespace SharedLibraries
{
    public class Commons
    {
        public static Boolean CheckExistInBinary(Int32 iA, Int32 iB, Boolean bisEquals)
        {
            if (bisEquals)
            {
                if (iA == iB)
                    return true;
                else
                    return false;
            }
            else
            {
                if (iA < iB)
                    return false;
                else if (iB == (iA & iB))
                    return true;
                return false;
            }
        }

        public static void setTags(Repeater rptTag, String lstTags)
        {
            if (rptTag != null && lstTags != null)
            {
                List<String> temp1 = StringEx.Split(lstTags, ',');
                if (temp1.Count > 0)
                {
                    var result = (from p in CustomerCache.get_lstCategory_ZipEO()
                                  join c in temp1
                                 on Convert.ToString(p.PK_iCategoryID) equals c.ToString()
                                  select new
                                  {
                                      sTag = p.sName,
                                      sTag_Link = OtherEx.AddDomainInUrl(p.sUrlRewrite)
                                  }).ToList();
                    if (result.Count > 0)
                    {
                        rptTag.DataSource = result;
                        rptTag.DataBind();
                        rptTag.Visible = true;
                    }
                }
            }
        }

        public static String createUniqueID(SEOEO _SEOEO)
        {
            if (_SEOEO != null)
                return Convert.ToString(_SEOEO.PK_iTable + "nmt" + _SEOEO.PK_iSEO);
            else
                return "404nmt404";
        }

        public static void setAccessDenied(System.Web.UI.Page ctrlPage, ThangNM.UserControl.MsgUC ctrlMsg)
        {
            String sUsername = ShareDAO.UserDAO.getPK_iAccountID(Convert.ToString(System.Web.HttpContext.Current.Session["secret"])).Name;
            if (ctrlMsg != null)
            {
                ctrlMsg.setNotifications(ConstEx.FunctionSetMsg.DANGER, String.Format(MessagesEx.Khong_Co_Quyen_Truy_Cap, sUsername));
            }
            (new Logs()).WriteLog_To_DB(new LogEO(String.Format(MessagesEx.ATTACH_TWO_INFO, sUsername , ctrlPage.Request.RawUrl), ConstEx.Log_iType.ACCOUNT_ACCESS_DENIAL), false);
        }

        public static void setSEO_ON_PAGE(System.Web.UI.Page ctrlPage, SEOEO _SEOEO, Type tType, Boolean isUpdateVisit = true)
        {
            if (ctrlPage == null || _SEOEO == null)
                return;
            if (String.IsNullOrEmpty(_SEOEO.sTitleEx))
                _SEOEO.sTitleEx = Commons.getTitle(_SEOEO.PK_iTable, _SEOEO.FK_sCategory, _SEOEO.sTitle, null);
            else
                _SEOEO.sTitleEx = Commons.getTitle(_SEOEO.PK_iTable, _SEOEO.FK_sCategory, _SEOEO.sTitle, _SEOEO.sTitleEx);
            ctrlPage.Page.Title = _SEOEO.sTitleEx;

            foreach (var item in Commons.getMetaTag_NEW(_SEOEO))
            {
                ctrlPage.Header.Controls.Add(item);
            }
            foreach (var item in Commons.getLinkTag_NEW(_SEOEO))
            {
                ctrlPage.Header.Controls.Add(item);
            }

            //string[] Code = Commons.Split(_SEOEO.sSourceCode, ',');
            //if (Code.Length > 0)
            //{
            //    var css1 = new HtmlGenericControl("link");
            //    css1.Attributes["type"] = "text/css";
            //    css1.Attributes["rel"] = "stylesheet";
            //    css1.Attributes["href"] = GetTextConstants.Topic_sCode_Link_GTC(Topic_sCode_C.shCore_css);
            //    ctrlPage.Page.Header.Controls.Add(css1);
            //    var css2 = new HtmlGenericControl("link");
            //    css2.Attributes["type"] = "text/css";
            //    css2.Attributes["rel"] = "stylesheet";
            //    css2.Attributes["href"] = GetTextConstants.Topic_sCode_Link_GTC(Topic_sCode_C.shThemeDefault_css);
            //    ctrlPage.Page.Header.Controls.Add(css2);

            //    var js1 = new HtmlGenericControl("script");
            //    js1.Attributes["type"] = "text/javascript";
            //    js1.Attributes["src"] = GetTextConstants.Topic_sCode_Link_GTC(Topic_sCode_C.shCore);
            //    ctrlPage.Page.Header.Controls.Add(js1);
            //    for (int i = 0; i < Code.Length; i++)
            //    {
            //        var js2 = new HtmlGenericControl("script");
            //        js2.Attributes["type"] = "text/javascript";
            //        js2.Attributes["src"] = GetTextConstants.Topic_sCode_Link_GTC(Convert.ToInt16(Code[i].ToString().Trim()));
            //        ctrlPage.Page.Header.Controls.Add(js2);
            //    }
            //    System.Web.UI.ClientScriptManager js3 = ctrlPage.Page.ClientScript;
            //    if (!js3.IsClientScriptBlockRegistered(tType, "SyntaxHighlighter"))
            //    {
            //        String jsText = "<script type=\"text/javascript\"> SyntaxHighlighter.all();</script>";
            //        js3.RegisterClientScriptBlock(tType, "SyntaxHighlighter", jsText.ToString());
            //    }
            //}

            if (isUpdateVisit)
            {
                System.Web.UI.ClientScriptManager js4 = ctrlPage.Page.ClientScript;
                if (!js4.IsClientScriptBlockRegistered(tType, "isVisit"))
                {
                    SEO_EXEO _SEO_EXEO = new SEO_EXEO() { PK_iSEO = _SEOEO.PK_iSEO, PK_iTable = _SEOEO.PK_iTable, iComment_iLike = _SEOEO.iComment, iComment_iVisit_iLike = 2, tTimeout = DateTime.Now.AddMinutes(1) };
                    String token = System.Web.HttpUtility.UrlEncodeUnicode(Security.Login.Encrypt(JsonEx.Object2Json(_SEO_EXEO), System.Configuration.ConfigurationManager.AppSettings["FACEBOOK"]));
                    String jsText = "<script type=\"text/javascript\">setTimeout(function () { fncComment_Visit_Like('" + token + "'); }, 8000);</script>";
                    js4.RegisterClientScriptBlock(tType, "isVisit", jsText.ToString());
                }
            }
        }

        public static List<HtmlMeta> getMetaTag_NEW(SEOEO _SEOEO, String sLinkMedia = "")
        {
            _SEOEO.sUrlRewrite = OtherEx.AddDomainInUrl(Convert.ToString(_SEOEO.sUrlRewrite));
            _SEOEO.sUrlShort = OtherEx.AddDomainInUrl(Convert.ToString(_SEOEO.sUrlShort));
            _SEOEO.sKeyword = _SEOEO.sKeyword + System.Configuration.ConfigurationManager.AppSettings["KEYWORD"];

            _SEOEO.sDescription = StringEx.Trim(StringEx.RemoveHtmlTagsUsingCharArray(_SEOEO.sDescription).PadRight(160));
            if (_SEOEO.sDescription.Length < 100)
                _SEOEO.sDescription = _SEOEO.sDescription + System.Configuration.ConfigurationManager.AppSettings["SLOGAN"];
            if (String.IsNullOrEmpty(StringEx.Trim(_SEOEO.sLinkImage)))
            {
                _SEOEO.sLinkImage = System.Configuration.ConfigurationManager.AppSettings["IMAGE"];
            }
            //String sLink = _SEOEO.sTitle.Split('|')[0].Split('-')[0];

            List<HtmlMeta> lstMetaTag = new List<HtmlMeta>();
            HtmlMeta metatag;
            metatag = new HtmlMeta();
            metatag.Name = "copyright";
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["COPYRIGHT"];
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "robots";
            metatag.Content = GetListConstants.getValueKeyInSortedList(GetListConstants.Robots_GLC(), _SEOEO.iRobots, false);
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "description";
            metatag.Content = _SEOEO.sDescription;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "keywords";
            metatag.Content = _SEOEO.sKeyword;
            lstMetaTag.Add(metatag);

            //<!-- Twitter Card data -->
            metatag = new HtmlMeta();
            metatag.Name = "twitter:card";
            metatag.Content = "summary";
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:site";
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["TWITTER"];
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:title";
            metatag.Content = _SEOEO.sTitleEx;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:description";
            metatag.Content = _SEOEO.sDescription;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:creator";
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["TWITTER"];
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:image:src";
            metatag.Content = _SEOEO.sLinkImage;
            lstMetaTag.Add(metatag);
            //<!-- Twitter Card data --> 


            //<!-- Schema.org markup for Google+ --> 
            metatag = new HtmlMeta();
            metatag.Attributes.Add("itemprop", "name");
            metatag.Content = _SEOEO.sTitleEx;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("itemprop", "description");
            metatag.Content = _SEOEO.sDescription;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("itemprop", "url");
            metatag.Content = _SEOEO.sUrlRewrite;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("itemprop", "image");
            metatag.Content = _SEOEO.sLinkImage;
            lstMetaTag.Add(metatag);
            //<!-- Schema.org markup for Google+ --> 


            //<!-- Open Graph data -->
            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:title");
            metatag.Content = _SEOEO.sTitleEx;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:type");
            metatag.Content = "article";
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:url");
            metatag.Content = _SEOEO.sUrlRewrite;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:image");
            metatag.Content = _SEOEO.sLinkImage;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:description");
            metatag.Content = _SEOEO.sDescription;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:site_name");
            metatag.Content = _SEOEO.sTitleEx;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "article:published_time");
            metatag.Content = _SEOEO.tDateTimeCreate.ToString("s");
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "article:modified_time");
            metatag.Content = _SEOEO.tDateTimeModify.ToString("s");
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "article:section");
            metatag.Content = _SEOEO.sKeyword;
            lstMetaTag.Add(metatag);


            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "article:tag");
            metatag.Content = _SEOEO.sKeyword;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "fb:admins");
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["FACEBOOK"];
            lstMetaTag.Add(metatag);



            if (Commons.getIsUseFlash(sLinkMedia))
            {
                string type = "application/x-shockwave-flash";
                switch (GetTextConstants.ExtendFile_GTC(System.IO.Path.GetExtension(sLinkMedia)))
                {
                    case ExtendFile_C.SWF: type = "application/x-shockwave-flash"; break;
                    case ExtendFile_C.MP4: type = "video/mp4"; break;
                }
                metatag = new HtmlMeta();
                metatag.Name = "medium";
                metatag.Content = "video";
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Name = "video_width";
                metatag.Content = "487";
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Name = "video_height";
                metatag.Content = "365";
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Name = "video_type";
                metatag.Content = type;
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Attributes.Add("property", "og:video");
                metatag.Content = sLinkMedia;
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Attributes.Add("property", "og:video:secure_url");
                metatag.Content = sLinkMedia.Replace("http://", "https://");
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Attributes.Add("property", "og:video:type");
                metatag.Content = type;
                lstMetaTag.Add(metatag);
            }
            //<!-- Open Graph data -->

            return lstMetaTag;
        }

        public static List<HtmlGenericControl> getLinkTag_NEW(SEOEO _SEOEO, String sLinkMedia = "")
        {
            _SEOEO.sUrlRewrite = OtherEx.AddDomainInUrl(Convert.ToString(_SEOEO.sUrlRewrite));
            _SEOEO.sUrlShort = OtherEx.AddDomainInUrl(Convert.ToString(_SEOEO.sUrlShort));

            if (String.IsNullOrEmpty(StringEx.Trim(_SEOEO.sLinkImage)))
            {
                _SEOEO.sLinkImage = System.Configuration.ConfigurationManager.AppSettings["IMAGE"];
            }
            //String sLink = _SEOEO.sTitle.Split('|')[0].Split('-')[0];
            List<HtmlGenericControl> lstLinkTag = new List<HtmlGenericControl>();
            HtmlGenericControl linktag;
            linktag = new HtmlGenericControl("link");
            linktag.Attributes["rel"] = "canonical";
            linktag.Attributes["href"] = _SEOEO.sUrlRewrite;
            lstLinkTag.Add(linktag);

            linktag = new HtmlGenericControl("link");
            linktag.Attributes["rel"] = "shortlink";
            linktag.Attributes["href"] = _SEOEO.sUrlShort;
            lstLinkTag.Add(linktag);

            if (Commons.getIsUseFlash(sLinkMedia))
            {
                linktag = new HtmlGenericControl("link");
                linktag.Attributes["rel"] = "image_src";
                linktag.Attributes["href"] = _SEOEO.sLinkImage;
                lstLinkTag.Add(linktag);

                linktag = new HtmlGenericControl("link");
                linktag.Attributes["rel"] = "video_src";
                linktag.Attributes["href"] = sLinkMedia;
                lstLinkTag.Add(linktag);
            }

            return lstLinkTag;
        }

        public static String getTitle(Int16 PK_iTable, String FK_sCategory, String param1, String param2)
        {
            String sTitle = "";
            switch (PK_iTable)
            {
                case ConstEx.TableID_C.Category:
                    if (!String.IsNullOrEmpty(param2))
                        sTitle = param1 + " | " + param2 + Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SLOGAN"]);
                    else
                        sTitle = param1 + Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SLOGAN"]);
                    break;
                case ConstEx.TableID_C.Topic:
                    sTitle = param1 + TitleSEO.BaiViet_Ex;
                    break;
                case ConstEx.TableID_C.Media:
                    if (StringEx.Compare(FK_sCategory, "308"))
                        sTitle = param1 + TitleSEO.CongCu_Ex;
                    else
                        sTitle = param1 + " | " + param2 + TitleSEO.GiaiTri_Ex;
                    break;
                case ConstEx.TableID_C.QuestionAnswer:
                    sTitle = param1 + TitleSEO.HoiDap_Ex;
                    break;
                case ConstEx.TableID_C.Account:
                    sTitle = param1 + " - " + param2 + TitleSEO.ThanhVien_Ex;
                    break;
                case ConstEx.TableID_C.File:
                    sTitle = param1 + TitleSEO.TaiFile_Ex;
                    break;
                default:
                    break;
            }
            return StringEx.TrimEx(sTitle);
        }


        public static void setBreadcrumb(SEOEO _SEOEO, Literal lblBreadcrumb)
        {
            Category_ZipEO _Category_ZipEO = new Category_ZipEO();
            switch (_SEOEO.PK_iTable)
            {
                case ConstEx.TableID_C.Topic:
                    lblBreadcrumb.Text =
                    "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                        "<a href=\"http://nguyenmanhthang.net/danh-muc\" itemprop=\"item\"><span itemprop=\"name\">Danh mục</span></a>" +
                        "<meta itemprop=\"position\" content=\"2\">" +
                    "</li>";
                    break;
                case ConstEx.TableID_C.Account:
                    lblBreadcrumb.Text =
                    "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                        "<a href=\"http://nguyenmanhthang.net/thanh-vien\" itemprop=\"item\"><span itemprop=\"name\">Thành viên</span></a>" +
                        "<meta itemprop=\"position\" content=\"2\">" +
                    "</li>";
                    break;
                case ConstEx.TableID_C.File:
                    lblBreadcrumb.Text =
                    "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                        "<a href=\"http://nguyenmanhthang.net/tai-file\" itemprop=\"item\"><span itemprop=\"name\">Tải file</span></a>" +
                        "<meta itemprop=\"position\" content=\"2\">" +
                    "</li>";
                    break;
                case ConstEx.TableID_C.Media:
                    if (StringEx.Compare(_SEOEO.FK_sCategory, "308"))
                    {
                        lblBreadcrumb.Text =
                        "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                            "<a href=\"http://nguyenmanhthang.net/cong-cu\" itemprop=\"item\"><span itemprop=\"name\">Công cụ</span></a>" +
                            "<meta itemprop=\"position\" content=\"2\">" +
                        "</li>";
                        return;
                    }
                    _Category_ZipEO = CustomerCache.get_lstCategory_ZipEO().Find(i => StringEx.Compare(i.PK_iCategoryID.ToString(), _SEOEO.FK_sCategory));
                    lblBreadcrumb.Text =
                    "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                        "<a href=\"http://nguyenmanhthang.net/giai-tri\" itemprop=\"item\"><span itemprop=\"name\">Giải trí</span></a>" +
                        "<meta itemprop=\"position\" content=\"2\">" +
                    "</li>";
                    if (_Category_ZipEO != null)
                    {
                        lblBreadcrumb.Text = lblBreadcrumb.Text +
                        "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                            "<a href=\"" + OtherEx.AddDomainInUrl(_Category_ZipEO.sUrlRewrite) + "\" itemprop=\"item\"><span itemprop=\"name\">" + _Category_ZipEO.sName + "</span></a>" +
                            "<meta itemprop=\"position\" content=\"2\">" +
                        "</li>";
                    }
                    break;
                case ConstEx.TableID_C.Category:
                    switch (Convert.ToInt16(Convert.ToString(_SEOEO.PK_iSEO).Substring(0, 1)))
                    {
                        case ConstEx.TableID_C.Topic:
                            lblBreadcrumb.Text =
                            "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                                "<a href=\"http://nguyenmanhthang.net/danh-muc\" itemprop=\"item\"><span itemprop=\"name\">Danh mục</span></a>" +
                                "<meta itemprop=\"position\" content=\"2\">" +
                            "</li>";
                            lblBreadcrumb.Text = lblBreadcrumb.Text +
                            "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                                "<a href=\"" + OtherEx.AddDomainInUrl(_SEOEO.sUrlRewrite) + "\" itemprop=\"item\"><span itemprop=\"name\">" + _SEOEO.sTitle + "</span></a>" +
                                "<meta itemprop=\"position\" content=\"2\">" +
                            "</li>";
                            break;
                        case ConstEx.TableID_C.Other:
                            lblBreadcrumb.Text =
                            "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                                "<a href=\"" + OtherEx.AddDomainInUrl(_SEOEO.sUrlRewrite) + "\" itemprop=\"item\"><span itemprop=\"name\">" + _SEOEO.sTitle + "</span></a>" +
                                "<meta itemprop=\"position\" content=\"2\">" +
                            "</li>";
                            break;
                        case ConstEx.TableID_C.Media:
                            //_Category_ZipEO = CustomerCache.get_lstCategory_ZipEO().Find(i => i.PK_iCategoryID == _SEOEO.PK_iSEO);
                            lblBreadcrumb.Text =
                            "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                                "<a href=\"http://nguyenmanhthang.net/giai-tri\" itemprop=\"item\"><span itemprop=\"name\">Giải trí</span></a>" +
                                "<meta itemprop=\"position\" content=\"2\">" +
                            "</li>";
                            lblBreadcrumb.Text = lblBreadcrumb.Text +
                            "<li itemprop=\"itemListElement\" itemscope=\"\" itemtype=\"http://schema.org/ListItem\">" +
                                "<a href=\"" + OtherEx.AddDomainInUrl(_SEOEO.sUrlRewrite) + "\" itemprop=\"item\"><span itemprop=\"name\">" + _SEOEO.sTitle + "</span></a>" +
                                "<meta itemprop=\"position\" content=\"2\">" +
                            "</li>";
                            break;
                    }
                    break;
            }
        }



        public static String get_sUrlRewrite_sUrlShort(Int16 iType, Boolean issUrlRewrite, String sCategory, String sTitle, Int16 iGroup = 0)
        {
            sTitle = StringEx.ConvertToUnSign(sTitle);
            String strUrl = "";
            if (issUrlRewrite)
            {
                switch (iType)
                {
                    case ConstEx.TableID_C.Category:
                        switch (iGroup)
                        {
                            case ConstEx.TableID_C.Category:
                            case ConstEx.TableID_C.Topic:
                                strUrl = FileNameByFunction.Danh_Muc_ + sTitle;
                                break;
                            case ConstEx.TableID_C.Media:
                                strUrl = FileNameByFunction.Giai_Tri_ + sTitle;
                                break;
                            case Media_iType_C.Ung_Dung:
                                strUrl = FileNameByFunction.Cong_Cu_ + sTitle + FileNameByFunction.ID_HTML;
                                break;
                        }
                        break;
                    case ConstEx.TableID_C.Topic:
                        strUrl = FileNameByFunction.Bai_Viet_ + sTitle + FileNameByFunction.ID_HTML;
                        break;
                    case ConstEx.TableID_C.Media:
                        strUrl = FileNameByFunction.Giai_Tri_ + sCategory + FileNameByFunction.Slash + sTitle + FileNameByFunction.ID_HTML;
                        break;
                    case ConstEx.TableID_C.QuestionAnswer:
                        strUrl = FileNameByFunction.Hoi_Dap_ + sTitle + FileNameByFunction.ID_HTML;
                        break;
                    case ConstEx.TableID_C.Account:
                        strUrl = FileNameByFunction.Tac_Gia_ + sTitle + FileNameByFunction.HTML;
                        break;
                    case ConstEx.TableID_C.File:
                        strUrl = FileNameByFunction.Tai_File_ + sTitle + FileNameByFunction.ID_HTML;
                        break;
                    case ConstEx.TableID_C.Tool:
                        strUrl = FileNameByFunction.Cong_Cu_ + sTitle + FileNameByFunction.ID_HTML;
                        break;
                    default:
                        break;
                }
            }
            else
            {
                switch (iType)
                {
                    case ConstEx.TableID_C.Category:
                        switch (iGroup)
                        {
                            case ConstEx.TableID_C.Category:
                            case ConstEx.TableID_C.Topic:
                                strUrl = FileNameByFunction.Category_c + FileNameByFunction.ID;
                                break;
                            case ConstEx.TableID_C.Media:
                                strUrl = FileNameByFunction.Media_g + FileNameByFunction.ID;
                                break;
                        }
                        break;
                    case ConstEx.TableID_C.Topic:
                        strUrl = FileNameByFunction.Topic_t + FileNameByFunction.ID;
                        break;
                    case ConstEx.TableID_C.Media:
                        strUrl = FileNameByFunction.Game_m + FileNameByFunction.ID;
                        break;
                    case ConstEx.TableID_C.QuestionAnswer:
                        strUrl = FileNameByFunction.Answer_q + FileNameByFunction.ID;
                        break;
                    case ConstEx.TableID_C.Account:
                        strUrl = FileNameByFunction.Author_u + FileNameByFunction.ID;
                        break;
                    case ConstEx.TableID_C.File:
                        strUrl = FileNameByFunction.Download_f + FileNameByFunction.ID;
                        break;
                    default:
                        break;
                }
            }
            return strUrl.ToLower();
        }

        //public static String getFullUrl(String sInput)
        //{
        //    return System.Configuration.ConfigurationManager.AppSettings["HOMEPAGE"] + sInput;
        //}

        //public static String getShowDateTime(DateTime tInput)
        //{
        //    return tInput.ToString(Format.Format_DateTime_WebView);
        //}

        //public void SetCookie(string name, string value, int expireDays)
        //{
        //    HttpCookie cookie = new HttpCookie(name);
        //    cookie.Value = value;
        //    cookie.Expires = DateTime.Now.AddDays(expireDays);
        //    Response.Cookies.Add(cookie);
        //}

        //public HttpCookie GetCookie(string name)
        //{
        //    return Request.Cookies[name];
        //}  

        //string abc = ConfigurationManager.AppSettings["abc"];
        //public static void EditAppSetting(string key, string value)
        //{
        //    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        //    config.AppSettings.Settings[key].Value = value;
        //    config.Save(ConfigurationSaveMode.Modified);
        //    ConfigurationManager.RefreshSection("appSettings");
        //}
        //public static void AddAppSetting(string key, string value)
        //{
        //    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        //    config.AppSettings.Settings.Add(key, value);
        //    config.Save(ConfigurationSaveMode.Modified);
        //    ConfigurationManager.RefreshSection("appSettings");
        //}
        //public static void RemoveAppSetting(string key)
        //{
        //    System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        //    config.AppSettings.Settings.Remove(key);
        //    config.Save(ConfigurationSaveMode.Modified);
        //    ConfigurationManager.RefreshSection("appSettings");
        //}  

        //public static void setInfoSitemap(ref SEOEO _SEOEO, Int16 iType)
        //{
        //switch (iType)
        //{
        //    case TypeSiteMap.Homepage:
        //        _SEOEO.changefreq = ChangeFreq_C.always;
        //        _SEOEO.priority = 1.00;
        //        _SEOEO.type = Category_iType_C.Category;
        //        break;
        //    case TypeSiteMap.Category_0:
        //        _SEOEO.changefreq = ChangeFreq_C.hourly;
        //        _SEOEO.priority = 0.90;
        //        _SEOEO.type = Category_iType_C.Category;
        //        break;
        //    case TypeSiteMap.Category_1:
        //        _SEOEO.changefreq = ChangeFreq_C.daily;
        //        _SEOEO.priority = 0.80;
        //        _SEOEO.type = Category_iType_C.Category;
        //        break;
        //    case TypeSiteMap.Category_2:
        //        _SEOEO.changefreq = ChangeFreq_C.daily;
        //        _SEOEO.priority = 0.60;
        //        _SEOEO.type = Category_iType_C.Category;
        //        break;
        //    case TypeSiteMap.Topic_0:
        //        _SEOEO.changefreq = ChangeFreq_C.weekly;
        //        _SEOEO.priority = 0.50;
        //        _SEOEO.type = Category_iType_C.Topic;
        //        break;
        //    case TypeSiteMap.Topic_1:
        //        _SEOEO.changefreq = ChangeFreq_C.monthly;
        //        _SEOEO.priority = 0.20;
        //        _SEOEO.type = Category_iType_C.Topic;
        //        break;
        //    case TypeSiteMap.Media_0:
        //        _SEOEO.changefreq = ChangeFreq_C.weekly;
        //        _SEOEO.priority = 0.20;
        //        _SEOEO.type = Category_iType_C.Media;
        //        break;
        //    case TypeSiteMap.Media_1:
        //        _SEOEO.changefreq = ChangeFreq_C.monthly;
        //        _SEOEO.priority = 0.10;
        //        _SEOEO.type = Category_iType_C.Media;
        //        break;
        //    case TypeSiteMap.QuestionAnswer:
        //        _SEOEO.changefreq = ChangeFreq_C.weekly;
        //        _SEOEO.priority = 0.20;
        //        _SEOEO.type = Category_iType_C.QuestionAnswer;
        //        break;
        //    case TypeSiteMap.Account:
        //        _SEOEO.changefreq = ChangeFreq_C.monthly;
        //        _SEOEO.priority = 0.10;
        //        _SEOEO.type = Category_iType_C.Account;
        //        break;
        //    case TypeSiteMap.File:
        //        _SEOEO.changefreq = ChangeFreq_C.monthly;
        //        _SEOEO.priority = 0.20;
        //        _SEOEO.type = Category_iType_C.File;
        //        break;
        //    case TypeSiteMap.Never:
        //        _SEOEO.changefreq = ChangeFreq_C.never;
        //        _SEOEO.priority = 0.10;
        //        _SEOEO.type = Category_iType_C.Topic;
        //        break;
        //}
        //}

        public static List<HtmlMeta> getMetaTag(MetaTagEO _MetaTagEO)
        {
            //if (!StringEx.Compare(_MetaTagEO.sCanonical, System.Configuration.ConfigurationManager.AppSettings["HOMEPAGE"]))
            _MetaTagEO.sCanonical = OtherEx.AddDomainInUrl(Convert.ToString(_MetaTagEO.sCanonical));
            //if (!StringEx.Compare(_MetaTagEO.sShortLink, System.Configuration.ConfigurationManager.AppSettings["HOMEPAGE"]))
            _MetaTagEO.sShortLink = OtherEx.AddDomainInUrl(Convert.ToString(_MetaTagEO.sShortLink));

            _MetaTagEO.sDescription = StringEx.Trim(StringEx.RemoveHtmlTagsUsingCharArray(_MetaTagEO.sDescription).PadRight(160));
            if (String.IsNullOrEmpty(StringEx.Trim(_MetaTagEO.sLinkImage)))
            {
                _MetaTagEO.sLinkImage = System.Configuration.ConfigurationManager.AppSettings["IMAGE"];
            }
            String sLink = _MetaTagEO.sTitle.Split('|')[0].Split('-')[0];
            List<HtmlMeta> lstMetaTag = new List<HtmlMeta>();
            HtmlMeta metatag;
            metatag = new HtmlMeta();
            metatag.Name = "copyright";
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["COPYRIGHT"];
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "robots";
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["ROBOTS"];
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "description";
            metatag.Content = _MetaTagEO.sDescription;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "keywords";
            metatag.Content = _MetaTagEO.sTag;
            lstMetaTag.Add(metatag);

            //<!-- Twitter Card data -->
            metatag = new HtmlMeta();
            metatag.Name = "twitter:card";
            metatag.Content = "summary";
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:site";
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["TWITTER"];
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:title";
            metatag.Content = _MetaTagEO.sTitle;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:description";
            metatag.Content = _MetaTagEO.sDescription;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:creator";
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["TWITTER"];
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Name = "twitter:image:src";
            metatag.Content = _MetaTagEO.sLinkImage;
            lstMetaTag.Add(metatag);
            //<!-- Twitter Card data --> 


            //<!-- Schema.org markup for Google+ --> 
            metatag = new HtmlMeta();
            metatag.Attributes.Add("itemprop", "name");
            metatag.Content = _MetaTagEO.sTitle;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("itemprop", "description");
            metatag.Content = _MetaTagEO.sDescription;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("itemprop", "url");
            metatag.Content = _MetaTagEO.sCanonical;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("itemprop", "image");
            metatag.Content = _MetaTagEO.sLinkImage;
            lstMetaTag.Add(metatag);
            //<!-- Schema.org markup for Google+ --> 


            //<!-- Open Graph data -->
            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:title");
            metatag.Content = _MetaTagEO.sTitle;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:type");
            metatag.Content = "article";
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:url");
            metatag.Content = _MetaTagEO.sCanonical;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:image");
            metatag.Content = _MetaTagEO.sLinkImage;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:description");
            metatag.Content = _MetaTagEO.sDescription;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "og:site_name");
            metatag.Content = _MetaTagEO.sTitle;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "article:published_time");
            metatag.Content = _MetaTagEO.tDateTimeCreate.ToString("s");
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "article:modified_time");
            metatag.Content = _MetaTagEO.tDateTimeModify.ToString("s");
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "article:section");
            metatag.Content = _MetaTagEO.sTag;
            lstMetaTag.Add(metatag);


            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "article:tag");
            metatag.Content = _MetaTagEO.sTag;
            lstMetaTag.Add(metatag);

            metatag = new HtmlMeta();
            metatag.Attributes.Add("property", "fb:admins");
            metatag.Content = System.Configuration.ConfigurationManager.AppSettings["FACEBOOK"];
            lstMetaTag.Add(metatag);



            if (Commons.getIsUseFlash(_MetaTagEO.sVideoSrc))
            {
                string type = "application/x-shockwave-flash";
                switch (GetTextConstants.ExtendFile_GTC(System.IO.Path.GetExtension(_MetaTagEO.sVideoSrc)))
                {
                    case ExtendFile_C.SWF: type = "application/x-shockwave-flash"; break;
                    case ExtendFile_C.MP4: type = "video/mp4"; break;
                }
                metatag = new HtmlMeta();
                metatag.Name = "medium";
                metatag.Content = "video";
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Name = "video_width";
                metatag.Content = "487";
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Name = "video_height";
                metatag.Content = "365";
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Name = "video_type";
                metatag.Content = type;
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Attributes.Add("property", "og:video");
                metatag.Content = _MetaTagEO.sVideoSrc;
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Attributes.Add("property", "og:video:secure_url");
                metatag.Content = _MetaTagEO.sVideoSrc.Replace("http://", "https://");
                lstMetaTag.Add(metatag);

                metatag = new HtmlMeta();
                metatag.Attributes.Add("property", "og:video:type");
                metatag.Content = type;
                lstMetaTag.Add(metatag);
            }
            //<!-- Open Graph data -->

            return lstMetaTag;
        }

        public static List<HtmlGenericControl> getLinkTag(MetaTagEO _MetaTagEO)
        {
            if (!StringEx.Compare(_MetaTagEO.sCanonical, System.Configuration.ConfigurationManager.AppSettings["HOMEPAGE"]))
                _MetaTagEO.sCanonical = System.Configuration.ConfigurationManager.AppSettings["HOMEPAGE"] + _MetaTagEO.sCanonical;
            if (!StringEx.Compare(_MetaTagEO.sShortLink, System.Configuration.ConfigurationManager.AppSettings["HOMEPAGE"]))
                _MetaTagEO.sShortLink = System.Configuration.ConfigurationManager.AppSettings["HOMEPAGE"] + _MetaTagEO.sShortLink;

            if (String.IsNullOrEmpty(StringEx.Trim(_MetaTagEO.sLinkImage)))
            {
                _MetaTagEO.sLinkImage = System.Configuration.ConfigurationManager.AppSettings["IMAGE"];
            }
            String sLink = _MetaTagEO.sTitle.Split('|')[0].Split('-')[0];
            List<HtmlGenericControl> lstLinkTag = new List<HtmlGenericControl>();
            HtmlGenericControl linktag;
            linktag = new HtmlGenericControl("link");
            linktag.Attributes["rel"] = "canonical";
            linktag.Attributes["href"] = _MetaTagEO.sCanonical;
            lstLinkTag.Add(linktag);

            linktag = new HtmlGenericControl("link");
            linktag.Attributes["rel"] = "shortlink";
            linktag.Attributes["href"] = _MetaTagEO.sShortLink;
            lstLinkTag.Add(linktag);

            if (Commons.getIsUseFlash(_MetaTagEO.sVideoSrc))
            {
                linktag = new HtmlGenericControl("link");
                linktag.Attributes["rel"] = "image_src";
                linktag.Attributes["href"] = _MetaTagEO.sLinkImage;
                lstLinkTag.Add(linktag);

                linktag = new HtmlGenericControl("link");
                linktag.Attributes["rel"] = "video_src";
                linktag.Attributes["href"] = _MetaTagEO.sVideoSrc;
                lstLinkTag.Add(linktag);
            }

            return lstLinkTag;
        }

        public static Boolean getIsUseFlash(String _strUrl)
        {
            _strUrl = StringEx.Trim(_strUrl);
            if (StringEx.Equals(System.IO.Path.GetExtension(_strUrl), ".swf"))
                return true;
            if (StringEx.Equals(System.IO.Path.GetExtension(_strUrl), ".mp4"))
                return true;

            return false;
        }

        public static string getSourceCodeUse(string sContent)
        {
            string selectedValue = "";
            if (sContent.Contains("brush:bash"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushBash;
            }
            if (sContent.Contains("brush:csharp"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushCSharp;
            }
            if (sContent.Contains("brush:cpp"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushCpp;
            }
            if (sContent.Contains("brush:css"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushCss;
            }
            if (sContent.Contains("brush:delphi"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushDelphi;
            }
            if (sContent.Contains("brush:diff"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushDiff;
            }
            if (sContent.Contains("brush:groovy"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushGroovy;
            }
            if (sContent.Contains("brush:jscript"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushJScript;
            }
            if (sContent.Contains("brush:java"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushJava;
            }
            if (sContent.Contains("brush:javafx"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushJavaFX;
            }
            if (sContent.Contains("brush:perl"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushPerl;
            }
            if (sContent.Contains("brush:php"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushPhp;
            }
            if (sContent.Contains("brush:plain"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushPlain;
            }
            if (sContent.Contains("brush:python"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushPython;
            }
            if (sContent.Contains("brush:ruby"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushRuby;
            }
            if (sContent.Contains("brush:scala"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushScala;
            }
            if (sContent.Contains("brush:sql"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushSql;
            }
            if (sContent.Contains("brush:vb"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushVb;
            }
            if (sContent.Contains("brush:xml"))
            {
                selectedValue = selectedValue + "," + Topic_sCode_C.shBrushXml;
            }
            if (String.IsNullOrEmpty(selectedValue))
                selectedValue = "";
            else
                selectedValue = selectedValue + ",";
            return selectedValue;
        }

        //public static string ReWrite_Url_301_Redirect(string strFileName, string strPathAndQuery)
        //{
        //    strFileName = strFileName.ToLower();
        //    string urlrewrite = "";
        //    switch (strFileName)
        //    {
        //        case FileNameByFunction.Answer: urlrewrite = ""; break;
        //        case FileNameByFunction.Author: urlrewrite = ""; break;
        //        case FileNameByFunction.Category: urlrewrite = ""; break;
        //        case FileNameByFunction.Contact: urlrewrite = ""; break;
        //        case FileNameByFunction.Default: urlrewrite = ""; break;
        //        case FileNameByFunction.Download: urlrewrite = ""; break;
        //        case FileNameByFunction.Game: urlrewrite = ""; break;
        //        case FileNameByFunction.Media: urlrewrite = ""; break;
        //        case FileNameByFunction.Question: urlrewrite = ""; break;
        //        case FileNameByFunction.Topic: urlrewrite = ""; break;
        //        case FileNameByFunction.WWW: urlrewrite = strPathAndQuery.Substring(1); break;
        //    }
        //    urlrewrite = System.Configuration.ConfigurationManager.AppSettings["HOMEPAGE"] + urlrewrite;
        //    return urlrewrite;
        //}

        public static string RegNewsLetter(String sEmail)
        {
            try
            {
                NewLetterEO _NewLetterEO = new NewLetterEO();
                _NewLetterEO.sEmail = StringEx.Trim(sEmail).ToLower();
                _NewLetterEO.tRegisterDate = DateTime.Now;

                List<NewLetterEO> lst = new List<NewLetterEO>();
                string StrPath = System.Web.HttpContext.Current.Server.MapPath("~/GlobalResources/Email.json");
                StrPath = System.IO.File.ReadAllText(StrPath);

                object temp = JsonEx.Json2ListObject(StrPath, lst.GetType());
                if (temp != null)
                    lst = (List<NewLetterEO>)temp;
                var dup = lst.FindAll(x => StringEx.Equals(x.sEmail, _NewLetterEO.sEmail));
                if (dup.Count > 0)
                {
                    return "Bạn đã đăng ký bằng email này rồi.";
                }
                lst.Add(_NewLetterEO);
                System.IO.File.WriteAllText(System.Web.HttpContext.Current.Server.MapPath("~/GlobalResources/Email.json"), JsonEx.ListObject2Json(lst));
                return "Đăng ký thành công.";
            }
            catch (Exception ex)
            {
                (new Logs()).WriteLog_To_DB(new LogEO(ex.ToString(), ConstEx.Log_iType.EXCEPTION), false);
                return "Đăng ký thất bại. Vui lòng thử lại.";
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sError"></param>
        /// <param name="iType">
        /// 1: Exception
        /// 2: 404
        /// 3: AccessDenied
        /// default(0): Other
        /// </param>
        //public static void WriteLogError(String sError, Int16 iType = Log_iType_C.Exception)
        //{
        //    try
        //    {
        //        ErrorEO _ErrorEO = new ErrorEO();
        //        if (System.Web.HttpContext.Current == null)
        //            _ErrorEO.sLink = "N/A";
        //        else
        //            _ErrorEO.sLink = OtherEx.getUrlStandard(Convert.ToString(System.Web.HttpContext.Current.Request.Url));
        //        _ErrorEO.tTime = DateTime.Now;
        //        _ErrorEO.sContent = StringEx.TrimEx(sError);

        //        string LogFolder = System.Configuration.ConfigurationManager.AppSettings["RawUrl_RootPath"] + "GlobalResources\\Logs\\";
        //        string LogFile = "";
        //        switch (iType)
        //        {
        //            case Log_iType_C.Exception: LogFile = LogFolder + "Exception_" + DateTime.Now.ToString("yyyyMMddHH") + ".log"; break;
        //            case Log_iType_C._404: LogFile = LogFolder + "404_" + DateTime.Now.ToString("yyyyMMddHH") + ".log"; break;
        //            case Log_iType_C.AccessDenied: LogFile = LogFolder + "AccessDenied_" + DateTime.Now.ToString("yyyyMMddHH") + ".log"; break;
        //            default: LogFile = LogFolder + "Other_" + DateTime.Now.ToString("yyyyMMddHH") + ".log"; break;
        //        }
        //        if (!Directory.Exists(LogFolder))
        //        {
        //            Directory.CreateDirectory(LogFolder);
        //        }
        //        //sError = sError.Replace(Environment.NewLine, ". ");
        //        using (StreamWriter sw = File.AppendText(LogFile))
        //        {
        //            //sw.WriteLine(DateTime.Now.ToString("[dd/MM/yyyy HH:mm:ss]") + ",\t\t" + sError);
        //            //sw.Close();
        //            sw.WriteLine(JsonEx.Object2Json(_ErrorEO) + ",");
        //            sw.Close();
        //        }
        //    }
                //catch (Exception ex)
                //{
                    //(new Logs()).WriteLog(new LogEO(ex.ToString(), ConstEx.Log_iType.EXCEPTION)); }
        //}

        public static void WaitSentMail(object source, System.Timers.ElapsedEventArgs e)
        {
            String sSubject = "";
            String sBody = "";
            String sPath = "";
            if (CustomerCache.lstEmailWaitSent.Count > 0)
            {
                foreach (var item in CustomerCache.lstEmailWaitSent)
                {
                    if (item.iStatus == Email_iStatus_C.WAIT)
                    {
                        switch (item.iType)
                        {
                            case Email_iType_C.Login: break;
                            case Email_iType_C.Notification_Comment:
                                sPath = CustomerCache.strUrlTempMail;
                                sSubject = "Thư thông báo có bình luận mới";
                                if (File.Exists(sPath))
                                    sBody = System.IO.File.ReadAllText(sPath);
                                sBody = sBody.Replace("[@sName]", item.sName);
                                sBody = sBody.Replace("[@sUrl1]", item.s1);
                                sBody = sBody.Replace("[@sUrl2]", item.s2);

                                break;
                        }
                        if (SharedLibraries.Commons.SendMail(item.sName, System.Configuration.ConfigurationManager.AppSettings["EMAIL"], item.sEmail, sSubject, sBody))
                            item.iStatus = Email_iStatus_C.OK;
                        else
                            item.iStatus = Email_iStatus_C.NOT_OK;
                    }
                }
            }
            sPath = CustomerCache.strUrlLogMail;
            if (!File.Exists(sPath))
                File.Create(sPath);
            using (StreamWriter newTask = new StreamWriter(sPath, false))
            {
                newTask.WriteLine(JsonEx.ListObject2Json(CustomerCache.lstEmailWaitSent));
                newTask.Close();
            }
        }




        public static int getFontSizeByQuantity(int iQuantity)
        {
            if (iQuantity < 5)
            {
                return 10;
            }
            if (iQuantity < 10)
            {
                return 12;
            }
            if (iQuantity < 30)
            {
                return 14;
            }
            if (iQuantity < 50)
            {
                return 16;
            }
            if (iQuantity < 80)
            {
                return 18;
            }
            if (iQuantity < 100)
            {
                return 20;
            }
            if (iQuantity >= 100)
            {
                return 24;
            }
            return 10;
        }

        public static string Replace4Vote(string str)
        {
            if (str != null && (!string.IsNullOrEmpty(str)))
            {
                return str.Replace("/", "-");
            }
            else
            {
                return "";
            }
        }

        public static string RemoveHtml(string text)
        {
            return Regex.Replace(text, "<[^>]*>", string.Empty);
        }

        //#region "GetID"
        //public static Int64 getPK_iTopicID(string sMaxID, Int16 iType)
        //{
        //    Int64 lOutput = 0;
        //    try
        //    {
        //        lOutput = Convert.ToInt64(iType + sMaxID.PadLeft(5, '0'));
        //        return lOutput;
        //    }
        //    catch
        //    {
        //        return lOutput;
        //    }
        //}

        //public static String getPK_iFunctionID(Int32 iFuncLeft, Int32 iFuncRight)
        //{
        //    return Convert.ToString(iFuncLeft) + Convert.ToString(iFuncRight).PadLeft(2, '0');
        //}
        //#endregion

        #region "Send Mail"
        public static bool SendMail(string YourName, string srcEmail, string desEmail, string Subject, string Content)
        {
            String FilterMail = "[NguyenManhThang.Net] ";
            SmtpClient SmtpServer = new SmtpClient();
            SmtpServer.Credentials = new System.Net.NetworkCredential("it.site44.com@gmail.com", "ydtndlpacvzspqid");
            SmtpServer.Port = 587;
            SmtpServer.Host = "smtp.gmail.com";
            SmtpServer.EnableSsl = true;
            MailMessage mail = new MailMessage();
            String[] addr = desEmail.Split(',');
            mail.From = new MailAddress(srcEmail, srcEmail, System.Text.Encoding.UTF8);
            Byte i;
            for (i = 0; i < addr.Length; i++)
                mail.To.Add(addr[i]);
            mail.Subject = FilterMail + Subject;
            mail.Bcc.Add("thang.991992@gmail.com");
            mail.Body = Content;
            mail.IsBodyHtml = true;
            mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            mail.ReplyTo = new MailAddress(srcEmail);
            SmtpServer.Send(mail);
            return true;
        }
        #endregion



    }
}